
struct Years(i64);

struct Days(i64);
impl Years {
    fn to_days(&self) -> Days {
        Days(self.0 * 365)
    }
}
impl Days {
    fn to_years(&self) -> Years {
        Years(self.0 / 365)
    }
}


fn old_enough(age: &Years) -> bool {
    age.0 >= 18
}


pub fn main(){
    let age = Years(5);
    println!("Old enough {}", old_enough(&age));

    let age_days = age.to_days();
    println!("Old enough {}", old_enough(&age_days.to_years()));


    //obtain the newtype's value as the base type , use tuple & destructuring

    let _years_as_primitive_1: i64 = age.0; //tuple 

    //ownership not changed  with destructuring
    let Years(years_as_primitive_2) = age; //destructuring & copy age 's base type to destructuring
    println!("years_as_primitive_2: {} , age.0: {}", years_as_primitive_2, age.0);
}
